package android.framework.binding;

import android.framework.binding.converters.IConverter;

public class BindingAdapter<T,G> implements IBindingAdapter<T, G>{

	private MultiBindingAdapter<G> listener = new MultiBindingAdapter<G>();
	
	private IConverter<T, G> converter;
	
	public BindingAdapter(IBindable<T> bindable, IConverter<T, G> converter){
		this.converter = converter;
		bindable.addListener(this);
	}
	
	public boolean notifyChanges(T value, long actionId) {
		if(listener != null){
			return listener.notifyChanges(converter.convertTo(value), actionId);
		}
		return false;
	}

	public void addListener(IObserver<G> listener) {
		this.listener.addObserver(listener);
	}

	public void setListener(MultiBindingAdapter<G> listener) {
		this.listener = listener;
	}

	public void removeListener(IObserver<G> listener) {
		this.listener.removeObserver(listener);
	}

	public void clearListeners() {
		this.listener.clear();
	}
	
	

}
